package com.cxs.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cxs.enums.OpenTypeEnum;
import com.cxs.mapper.SeatMapper;
import com.cxs.mapper.SeatOrderMapper;
import com.cxs.entity.Classroom;
import com.cxs.service.ClassroomService;
import com.cxs.mapper.ClassroomMapper;
import com.cxs.entity.bo.SeatBo;
import com.cxs.entity.vo.SeatInfoVO;
import com.cxs.entity.vo.SeatListInfoVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName: ClassroomServiceImpl
 * @description:
 * @author: 诗涵
 * @create: 2024-01-07 08:17
 */
@Service
public class ClassroomServiceImpl extends ServiceImpl<ClassroomMapper, Classroom>
    implements ClassroomService{

    @Autowired
    private ClassroomMapper classroomMapper;

    @Autowired
    private SeatMapper seatMapper;

    @Autowired
    private SeatOrderMapper seatOrderMapper;

    @Override
    public SeatInfoVO getSeatListInfo(Classroom classroom, LocalDate date) {
        SeatInfoVO res = new SeatInfoVO();
        Classroom clazz = classroomMapper.selectById(classroom.getId());
        BeanUtils.copyProperties(clazz, res);
        res.setOpenTypeDesc(OpenTypeEnum.getDesc(clazz.getOpenType()));
        List<SeatBo> seatInfoList = seatMapper.selectSeatInfoAndOrderInfo(clazz.getId(), date);
        List<SeatListInfoVO> list = CollectionUtils.isEmpty(seatInfoList) ? new ArrayList<>(0) : seatInfoList.stream().map(r -> {
            SeatListInfoVO vo = new SeatListInfoVO();
            BeanUtils.copyProperties(r, vo);
            return vo;
        }).collect(Collectors.toList());
        res.setList(list);
        return res;
    }
}




